#include<iostream>
using namespace std;

#define int long long

int a , b , p;
int qpow(int a , int b , int p)
{
    int ret = 0;
    while(b)
    {
        if(b & 1) ret = (ret + a) % p;
        a = (a + a) % p;
        b >>= 1;
    }
    return ret;
}
signed main()
{
    cin >> a >> b >> p;
    cout << qpow(a,b,p) << endl;
    return 0;
}